$(function(){
	/**角色初始化*/
	/*$('#roleIds').combobox({
        url:'role/roles',
        method:'get',
        valueField:'id',
        textField:'name',
        panelHeight:'auto',
        multiple:true,
        required : true,
        editable : false,
        tipPosition : 'bottom',
        missingMessage : '请为该项目（指标）分配角色'
    });
	var _roleIdsStr = $('#roleIdsStr').val();
	if (_roleIdsStr) {
		var _roleIdsStr = $('#roleIdsStr').val();
		var id_arr = _roleIdsStr.split(',');
		$('#roleIds').combobox('setValues', id_arr);
	}*/
	$('#parentId').combotree({
	    url : 'projectIndex/projectIndexs',
	    onLoadSuccess : function (node, data) {
			 var t = $(this);
	  		 if(data){
			     $(data).each(function(index,d){
					if(this.state == 'closed'){
					    t.tree('expandAll');
					}
			     });
			}
		}
	});
	//$('#parentId').combotree('setValue', $('#parentIdValue').val());
	$('#pId_clear_btn').click(function(){
		$('#parentId').combotree('clear');
	});
	$('#name').validatebox({
		required : true,
		tipPosition : 'bottom',
		missingMessage : '名称不能为空'
	});
	$('#seq').numberbox({
		required : true,
		min : 0,
		tipPosition : 'bottom',
		missingMessage : '顺序不能空,且大于等于0'
	});
	
	var weight_value = $('#weightValue').val();
	$('#weight').numberbox({
		required : false,
		min : 0,
		precision:1,
		value : weight_value || 1.0,
		tipPosition : 'bottom',
		invalidMessage : '权重大于等于0'
	});
	
	/** 保存 */
	$('#btnSave').click(function(){
		$('#name').validatebox({
			required : true,
			missingMessage : '名称不能为空'
		});
		$('#seq').numberbox({
			required : true,
			min : 0,
			tipPosition : 'bottom',
			missingMessage : '顺序不能空,且大于等于0'
		});
		$('#weight').numberbox({
			min : 0,
			precision:1,
			tipPosition : 'bottom',
			invalidMessage : '权重大于等于0'
		});
		var valid = $('#form').form('validate');
		//console.log(valid);
		if(valid) {
			$('#form').ajaxSubmit({
				url : 'projectIndex/save',
				success : function(data) {
					if (!data.success) {
						$.messager.alert('提醒', data.message, 'info');
					} else {
						$.messager.alert('提醒', data.message, 'info', function(){
							$('#form').form('clear');
							parent.reSearch();
							parent.closeEasyUiWindow('win');
						});
					}
				}
			});
		}
	});
	
	/** 取消 */
	$('#btnCancel').click(function(){
		$('#form').form('clear');
		parent.reSearch();
		parent.closeEasyUiWindow('win');
	});
});